from . import db
import datetime


class RoadToll(db.Model):
    __tablename__ = "li_road_toll"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    enterance = db.Column(db.String(256), doc="入口")
    export = db.Column(db.String(256), doc="出口")
    price = db.Column(db.Float, doc="价格", default=0)
    engineer = db.Column(db.String(64), doc="工程师")
    remarks = db.Column(db.Text, doc="备注")
    create_time = db.Column(db.DateTime, doc="时间", default=datetime.datetime.utcnow())
    user = db.Column(db.Integer, db.ForeignKey("li_user.id", ondelete="CASCADE"))
    car = db.Column(db.Integer, db.ForeignKey("li_car_info.id", ondelete="CASCADE"))
    deleted = db.Column(db.Boolean, default=False)
    images = db.relationship(
        "RoadTollImage",
        backref="road_tolls",
        lazy="dynamic",
        passive_deletes=False,
        cascade="delete",
    )


class RoadTollImage(db.Model):
    ___tablename__ = "li_road_toll_image"
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    file = db.Column(db.String(256), default="", doc="文件")
    road_toll = db.Column(db.Integer, db.ForeignKey("li_road_toll.id", ondelete="CASCADE"))
